/**
 * 配置层
 * 功能：
 *      1. 从json配置文件中读取配置参数
 *      2. 将数据保存起来
 *      3. 开放接口，供其他的js文件调用这里的参数
 */
var os = require("./nOs.js")

function GetParam() {
    var path = "/config.json";
    var jsonData = os.nReadFile(path);
    os.nDeleteFile(path);
    var config = JSON.parse(jsonData);
    return config;
}

function SaveParam(parm) {
    var paramDict = {
        "Uart": {
            "uartPort": "serial1"
        },
        "DeviceID": parm.DeviceID,
        "AP": {
            "ssid": "INESA_Gatewayzzh",
            "passWord": "1234567890"
        },
        "WIFI": {
            "ssid": parm.SSID,
            "passWord": parm.PWD
        },
        "MQTT": {
            "clientID": "HaaS 510-AS",
            "userName": "espressif",
            "passWord": "1234567890",
            "brokerIp": parm.ServerIP,
            "subTopic": "abc",
            "pubTopic": "topic",
            "payLoad": "test",
            "ADDR": parm.ADDR
        }
    };
    var path = "/config.json";
    console.log(JSON.stringify(paramDict));
    os.nWriteFile(path, JSON.stringify(paramDict));
    os.nDeleteFile(path);
}

module.exports = {
    GetParam: GetParam,
    SaveParam: SaveParam
}
